Skip to content

Fix GH-13012: DOMNode::isEqualNode() is incorrect when attribute order is different #13017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

nielsdos
Copy link
Member

Attributes (and namespace declarations) have to be compared in an unordered way.

…rder is different

Attributes (and namespace declarations) have to be compared in an
unordered way.
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nielsdos nielsdos closed this in 93951cf Dec 27, 2023
@orlitzky
Copy link
Contributor

I'm getting a new test failure in 8.3.2 and this is my prime suspect:

$ cat DOMNode_isEqualNode.diff 
--
     --- Test documents ---
     bool(true)
     bool(false)
079- bool(true)
079+ bool(false)
     bool(false)
     bool(false)
     bool(false)
--

Anything I can do to help debug it?

@nielsdos
Copy link
Member Author

@orlitzky that's a libxml2 bug: https://gitlab.gnome.org/GNOME/libxml2/-/issues/634
In general, libxml2 2.12.0 and 2.12.1 are very buggy and I advice to avoid those 2 versions, libxml2 2.12.2 should be fine.

@orlitzky
Copy link
Contributor

I'm getting the test failure with 2.11.15 and 2.11.16 💀

@nielsdos
Copy link
Member Author

@orlitzky I just compiled and tested these libxml2 versions:
2.11.5 works
2.11.6 works
2.12.0 broken
2.12.1 broken
2.12.2 works

Specifically, this line is failing for you: var_dump($dom1->isEqualNode($dom1Clone));.
In other words: cloning a document does not create the same document.

Could you please apply the following change to the test file DOMNode_isEqualNode.phpt and report back the output?

diff --git a/ext/dom/tests/DOMNode_isEqualNode.phpt b/ext/dom/tests/DOMNode_isEqualNode.phpt
index 94031aa797..953c9a6e82 100644
--- a/ext/dom/tests/DOMNode_isEqualNode.phpt
+++ b/ext/dom/tests/DOMNode_isEqualNode.phpt
@@ -206,6 +206,7 @@ function comparePairs($list1, $list2) {
 $dom1Clone = clone $dom1;
 var_dump($dom1->documentElement->isEqualNode($dom1Clone->documentElement));
 var_dump($dom1->documentElement->isEqualNode($dom2->documentElement));
+var_dump($dom1->saveXML(), $dom1Clone->saveXML());
 var_dump($dom1->isEqualNode($dom1Clone));
 var_dump($dom1->isEqualNode($dom2));
 var_dump($dom1->documentElement->isEqualNode($dom1Clone));

@orlitzky
Copy link
Contributor

Ah, crap. It was the fix for CVE-2023-45322 in libxml that is causing the regression, and we've backported it to 2.11.x. There's a newer fix in https://gitlab.gnome.org/GNOME/libxml2/-/commit/8707838e69f9c6e729c1d1d46bb3681d9e622be5. I'll ping the libxml maintainers to see if they can update the patch. Not a PHP issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DOMNode::isEqualNode() is incorrect when attribute order is different
3 participants